﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace ClothingShopping.Dto
{
    public class ResultOutput<T> : IResultOutput<T>
    {

        public bool IsSuccess {  get; private set; }

        public string? Msg { get;private set; }

        public T? Data { get; private set; }

        /// <summary>
        /// 数据总数
        /// </summary>
        public long Count { get; set; }

        public ResultOutput<T> Ok(T? data, string? msg)
        {
            IsSuccess = true;
            Msg = msg;
            Data = data;
            return this;
        }
        public ResultOutput<T> Ok(T? data,long count, string? msg)
        {
            IsSuccess = true;
            Msg = msg;
            Count = count;
            Data = data;
            return this;
        }

        public ResultOutput<T> Error(string msg,T? data=default)
        {
            IsSuccess = false;
            Msg = msg;
            Data = data;
            return this;
        }

        public ResultOutput<T> Error(string msg,long count ,T? data)
        {
            IsSuccess = false;
            Msg = msg;
            Count = count;
            Data = data;
            return this;
        }
    }

    public static class ResultOutput
    {
        public static IResultOutput<T> Ok<T>(T data,string? msg=null)
        {
            return new ResultOutput<T>().Ok(data,msg);
        }

        public static IResultOutput<T> Ok<T>(T data,long count, string? msg=null)
        {
            return new ResultOutput<T>().Ok(data, count, msg);
        }
        public static IResultOutput<T> Error<T>(string msg,T? data=default)
        {
            return new ResultOutput<T>().Error(msg,data);
        }

        public static IResultOutput Error(string msg)
        {
            return new ResultOutput<string>().Error(msg);
        }
    }
}
